home *** CD-ROM | disk | FTP | other *** search
/ Macworld Expo - Develope…Central & Net Innovations / Developer Central and Net Innovators (MacWorld Expo) (January 1999).iso / Developer Central / Bowers Development / Demo AppMaker / Examples / Pascal OS8 / Everything / Stuff.p < prev   
Encoding:
Text File  |  1998-10-30  |  8.4 KB  |  435 lines  |  [TEXT/CWIE]

  1. { Stuff.p }
  2. { Created 10/30/98 1:06 PM by AppMaker }
  3.  
  4. Unit Stuff;
  5. Interface
  6.  
  7. Uses
  8.     Types,
  9.     Quickdraw,
  10.     Controls,
  11.     Dialogs,
  12.     Events,
  13.     Lists,
  14.     Menus,
  15.     Resources,
  16.     TextEdit,
  17.     ToolUtils,
  18.  
  19.     DDocData,
  20.     EverythingEngine,
  21.     EverythingDoc,
  22.     AMWindow;
  23.  
  24. type
  25.     Stuff        = object (AMWindow)
  26.  
  27.     {data members}
  28.         mData:            DDocData;
  29.         mToolsHandle:        ControlHandle;
  30.         mPopupsHandle:        ControlHandle;
  31.         mFromValuesList2Handle:        ControlHandle;
  32.         mFromMenuHandle:        ControlHandle;
  33.         mListsHandle:        ControlHandle;
  34.         mTextListHandle:        ControlHandle;
  35.  
  36.     {methods}
  37.         Procedure Initialize; Override;
  38.  
  39.         Procedure Open        (inDoc:        EverythingDoc;
  40.                              inData:    DDocData);
  41.         Procedure Close; Override;
  42.  
  43.         Procedure Control    (whichControl:    ControlHandle;
  44.                               whichPart:        integer;
  45.                              where:            Point); Override;
  46.         Procedure MouseIn    (where:            Point;
  47.                              modifiers:        integer); Override;
  48.         Procedure TypeIn    (charCode:        SInt16); Override;
  49.         Procedure ExitCurField; Override;
  50.         Procedure DataChanged    (inDataID:    longint); Override;
  51.         Procedure Resize; Override;
  52.         Procedure Scroll    (newValue:        integer;
  53.                              oldValue:        integer); Override;
  54.  
  55.         Function  GetEngine: EverythingEngine;
  56.  
  57. Procedure BuildTextListList    (inControl:        ControlHandle);
  58. {$ifc false}
  59.         Procedure UpdateMenus; Override;
  60. {$endif}
  61.         Function  DoCommand        (inCommand:    longint): Boolean; Override;
  62.  
  63.         Procedure DoUndo;
  64.         Procedure DoCut;
  65.         Procedure DoCopy;
  66.         Procedure DoPaste;
  67.         Procedure DoClear;
  68.         Procedure DoSelectAll;
  69.         Procedure DoShowClipboard;
  70.  
  71.     end;
  72.  
  73. {----------}
  74. Procedure CreateStuff    (inDoc:        EverythingDoc;
  75.                              inData:    DDocData);
  76.  
  77. {----------}
  78. Implementation
  79.  
  80. Uses
  81.     Globals,
  82.     ResourceDefs,
  83.     DoScrap,
  84.     Scrolling,
  85.     ControlUtils,
  86.     Miscellany;
  87.  
  88. const
  89.     kToolsPalette        = 1;
  90.     kPopupsBox        = 2;
  91.     kFromValuesList2Popup        = 3;
  92.     kFromMenuPopup        = 4;
  93.     kListsBox        = 5;
  94.     kTextListList        = 6;
  95.  
  96. {----------}
  97. Procedure CreateStuff (
  98.     inDoc:        EverythingDoc;
  99.     inData:        DDocData);
  100. var
  101.     winObj:        Stuff;
  102. begin
  103.     winObj := nil;
  104.     New (winObj);
  105.  
  106.     if winObj <> nil then begin
  107.         winObj.Initialize;
  108.         winObj.Open (inDoc, inData);
  109.     end;
  110. end;
  111.  
  112. {----------}
  113. Procedure Stuff.Initialize;
  114. begin
  115.     Inherited Initialize;
  116. end;
  117.  
  118. {----------}
  119. Function  Stuff.GetEngine: EverythingEngine;
  120. begin
  121.     GetEngine := EverythingEngine (mDoc.mEngine);
  122. end;
  123.  
  124. {----------}
  125. Procedure Stuff.Open (
  126.     inDoc:        EverythingDoc;
  127.     inData:        DDocData);
  128. var
  129.     window:        WindowPtr;
  130.     wftb:        Handle;
  131.     errCode:    OSErr;
  132. begin
  133.     mDoc := inDoc;
  134.     mData := inData;
  135.     mData.AddResponder (self);
  136.  
  137.     window := GetNewCWindow (WIND_Stuff, nil, WindowPtr (-1));
  138.     if inDoc.mEngine.GetFilename <> '' then begin
  139.         SetWTitle (window, inDoc.mEngine.GetFilename);
  140.     end;
  141.     mWindow := window;
  142.     EverythingDoc (mDoc).mStuffPtr := window;
  143.  
  144.     WindowPeek (window)^.windowKind := kAMWindowFlag;
  145.     SetWRefCon (window, ord4 (self));
  146.     SetPort (window);
  147.     SetInfo (window);
  148.  
  149.     wftb := GetResource ('Wftb', WIND_Stuff);
  150.  
  151.     errCode := CreateRootControl (window, mRootControl);
  152.  
  153.     vScroll := nil;
  154.     hScroll := nil;
  155.  
  156.  
  157.     mToolsHandle := GetNewControl (CNTL_Tools, window);
  158.     SetWindowItemFont (mToolsHandle, wftb, 1);
  159.     SetControlValue (mToolsHandle, mData.GetTools);
  160.  
  161.     mPopupsHandle := GetNewControl (CNTL_Popups, window);
  162.     SetWindowItemFont (mPopupsHandle, wftb, 2);
  163.  
  164.     mFromValuesList2Handle := GetNewControl (CNTL_FromValuesList2, window);
  165.     errCode := EmbedControl (mFromValuesList2Handle, mPopupsHandle);
  166.     SetWindowItemFont (mFromValuesList2Handle, wftb, 3);
  167.     SetControlValue (mFromValuesList2Handle, mData.GetFromValuesList2);
  168.  
  169.     mFromMenuHandle := GetNewControl (CNTL_FromMenu, window);
  170.     errCode := EmbedControl (mFromMenuHandle, mPopupsHandle);
  171.     SetWindowItemFont (mFromMenuHandle, wftb, 4);
  172.     SetControlValue (mFromMenuHandle, mData.GetFromMenu);
  173.  
  174.     mListsHandle := GetNewControl (CNTL_Lists, window);
  175.     SetWindowItemFont (mListsHandle, wftb, 5);
  176.  
  177.     mTextListHandle := GetNewControl (CNTL_TextList, window);
  178.     errCode := EmbedControl (mTextListHandle, mListsHandle);
  179.     SetWindowItemFont (mTextListHandle, wftb, 6);
  180.     BuildTextListList (mTextListHandle);
  181.     SetListBoxChoice (mTextListHandle, mData.GetTextList);
  182.  
  183.     errCode := AdvanceKeyboardFocus (window);
  184.  
  185.     ShowWindow (window);
  186. end;
  187.  
  188. {----------}
  189. Procedure Stuff.Close;
  190. begin
  191.     mData.RemoveResponder (self);
  192.  
  193.     EverythingDoc (mDoc).mStuffPtr := nil;
  194.     SetInfo (nil);
  195.     HideWindow (mWindow);
  196.     DisposeWindow (mWindow);
  197.  
  198.     Dispose (self);
  199. end;
  200.  
  201. {----------}
  202. Procedure Stuff.BuildTextListList (
  203.     inControl:        ControlHandle);
  204. var
  205.     list:        ListHandle;
  206. begin
  207.     list := GetListHandle (inControl);
  208.     AddToList ("One",   list);
  209.     AddToList ("Two",   list);
  210.     AddToList ("Three", list);
  211.     AddToList ("Infinity",  list);
  212.  
  213. end;
  214.  
  215. {----------}
  216. Procedure Stuff.Control (
  217.     whichControl:    ControlHandle;
  218.     whichPart:        integer;
  219.     where:            Point);
  220. var
  221.     bounds:            Rect;
  222.     newValue:        integer;
  223.     partcode:        SInt16;
  224. begin
  225.     ExitCurField ();
  226.  
  227.     if whichControl = mToolsHandle then begin
  228.         if TrackClick (mToolsHandle, where) then begin
  229.             mData.SetTools (GetControlValue (mToolsHandle));
  230.         end;
  231.     end;
  232.     if whichControl = mFromValuesList2Handle then begin
  233.         if TrackClick (mFromValuesList2Handle, where) then begin
  234.             mData.SetFromValuesList2 (GetControlValue (mFromValuesList2Handle));
  235.         end;
  236.     end;
  237.     if whichControl = mFromMenuHandle then begin
  238.         if TrackClick (mFromMenuHandle, where) then begin
  239.             mData.SetFromMenu (GetControlValue (mFromMenuHandle));
  240.         end;
  241.     end;
  242.     if whichControl = mTextListHandle then begin
  243.         if TrackClick (mTextListHandle, where) then begin
  244.             mData.SetTextList (GetListBoxChoice (mTextListHandle));
  245.         end;
  246.     end;
  247. end;
  248.  
  249. {----------}
  250. Procedure Stuff.DataChanged (
  251.     inDataID:        longint);
  252. begin
  253.     if inDataID = idTools then begin
  254.         SetControlValue (mToolsHandle, mData.GetTools);
  255.     end;
  256.     if inDataID = idFromValuesList2 then begin
  257.         SetControlValue (mFromValuesList2Handle, mData.GetFromValuesList2);
  258.     end;
  259.     if inDataID = idFromMenu then begin
  260.         SetControlValue (mFromMenuHandle, mData.GetFromMenu);
  261.     end;
  262. End;
  263.  
  264. {----------}
  265. Procedure Stuff.MouseIn (
  266.     where:            Point;
  267.     modifiers:        integer);
  268. var
  269.     bounds:            Rect;
  270. begin
  271. end;
  272.  
  273. {----------}
  274. Procedure Stuff.ExitCurField;
  275. var
  276.     errCode:    OSErr;
  277.     focus:        ControlHandle;
  278. begin
  279.     errCode := GetKeyboardFocus (mWindow, focus);
  280.  
  281.     if focus = nil then begin
  282.         { nothing to exit }
  283.  
  284.     end;
  285.     inherited ExitCurField;
  286. end;
  287.  
  288. {----------}
  289. Procedure Stuff.TypeIn (
  290.     charCode:    SInt16);
  291. var
  292.     ch:            char;
  293.     errCode:    OSErr;
  294.     focus:        ControlHandle;
  295.     keyCode:    SInt16;
  296.     partcode:    SInt16;
  297. begin
  298.     errCode := GetKeyboardFocus (mWindow, focus);
  299.  
  300.     ch := chr (charCode);
  301.     if (ch = charEnter)
  302.     |  (ch = charReturn) then begin
  303.         ExitCurField;
  304.     end else if ch = charEsc then begin
  305.     end else if ch = charTab then begin
  306.         DoTab (BAnd (curEvent.modifiers, optionKey) <> 0);
  307.     end else if focus <> nil then begin
  308.         keyCode := BAnd (curEvent.message, keyCodeMask);
  309.         partcode := HandleControlKey (focus, keyCode, charCode, curEvent.modifiers);
  310.         mDoc.mEngine.SetDirty;
  311.     end else begin
  312.         SysBeep (1);
  313.     end;
  314. end;
  315.  
  316. {----------}
  317. Procedure Stuff.Resize;
  318. begin
  319.     { application-specific code to resize items in window }
  320. end;
  321.  
  322. {----------}
  323. Procedure Stuff.Scroll (
  324.     newValue:    integer;
  325.     oldValue:    integer);
  326. begin
  327.     { application-specific code to scroll window }
  328.     if gWhichScroll = vScroll then begin
  329.     end else begin    { horizontal }
  330.     end;
  331. end;
  332.  
  333. {----------}
  334. Procedure Stuff.DoUndo;
  335. begin
  336. end; {DoUndo}
  337.  
  338. {----------}
  339. Procedure Stuff.DoCut;
  340. var
  341.     curTE:        TEHandle;
  342. begin
  343.     curTE := GetCurTE ();
  344.  
  345.     if curTE <> nil then begin
  346.         TECut (curTE);
  347.         mDoc.mEngine.SetDirty;
  348.         scrapDirty := true;
  349.     end;
  350. end; {DoCut}
  351.  
  352. {----------}
  353. Procedure Stuff.DoCopy;
  354. var
  355.     curTE:        TEHandle;
  356. begin
  357.     curTE := GetCurTE ();
  358.  
  359.     if curTE <> nil then begin
  360.         TECopy (curTE);
  361.         scrapDirty := true;
  362.     end;
  363. end; {DoCopy}
  364.  
  365. {----------}
  366. Procedure Stuff.DoPaste;
  367. var
  368.     curTE:        TEHandle;
  369. begin
  370.     curTE := GetCurTE ();
  371.  
  372.     if curTE <> nil then begin
  373.         TEPaste (curTE);
  374.         mDoc.mEngine.SetDirty;
  375.     end;
  376. end; {DoPaste}
  377.  
  378. {----------}
  379. Procedure Stuff.DoClear;
  380. var
  381.     curTE:        TEHandle;
  382. begin
  383.     curTE := GetCurTE ();
  384.  
  385.     if curTE <> nil then begin
  386.         TEDelete (curTE);
  387.         mDoc.mEngine.SetDirty;
  388.     end;
  389. end; {DoClear}
  390.  
  391. {----------}
  392. Procedure Stuff.DoSelectAll;
  393. var
  394.     curTE:        TEHandle;
  395. begin
  396.     curTE := GetCurTE ();
  397.  
  398.     if curTE <> nil then begin
  399.         TESetSelect (0, 32767, curTE);
  400.     end;
  401. end; {DoSelectAll}
  402.  
  403. {----------}
  404. Procedure Stuff.DoShowClipboard;
  405. begin
  406. end; {DoShowClipboard}
  407.  
  408. {----------}
  409. Function Stuff.DoCommand (
  410.     inCommand:        longint): Boolean;
  411. begin
  412.     DoCommand := true;
  413.     case inCommand of
  414.         cmdUndo:
  415.                 DoUndo;
  416.         cmdCut:
  417.                 DoCut;
  418.         cmdCopy:
  419.                 DoCopy;
  420.         cmdPaste:
  421.                 DoPaste;
  422.         cmdClear:
  423.                 DoClear;
  424.         cmdSelectAll:
  425.                 DoSelectAll;
  426.         cmdShowClipboard:
  427.                 DoShowClipboard;
  428.  
  429.         otherwise
  430.                 DoCommand := false;
  431.     end; {case}
  432. end;
  433.  
  434. end.
  435.